{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Pixie 101: Quick Start Walkthrough",
      "provenance": [],
      "collapsed_sections": [
        "fSka7HxFC071"
      ],
      "toc_visible": true,
      "authorship_tag": "ABX9TyPFlUgJSQgiAZExNH8tiUzM",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/pixie-labs/pixie/blob/stats_colab/pxl_scripts/colab_notebooks/User-guide_Infra-stats.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bSSPc6x3YfEh",
        "colab_type": "text"
      },
      "source": [
        "<h1>How to use Pixie to monitor the health of your K8s infrastructure</h1>\n",
        "\n",
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5_nIjxb9eotR",
        "colab_type": "text"
      },
      "source": [
        "### Setup Pixie"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AP3y8XASsD8u",
        "colab_type": "text"
      },
      "source": [
        "*Prerequisites*\n",
        "\n",
        "*   You'll need to have Pixie running in a K8s environment already\n",
        "*   You'll need a google account to run this notebook"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Kd5yXJJOdUsM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Install CLI in this environment and authorize\n",
        "\n",
        "# Notes: \n",
        "## Hit enter when prompted for path\n",
        "## Click on prompted auth URL and manually enter key \n",
        "\n",
        "!bash -c \"$(curl -fsSL https://withpixie.ai/install.sh)\""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pfhZCpHxd-z4",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Verify px can access your cluster and platform is healthy\n",
        "\n",
        "!px get viziers"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "p-Gng5b5eHnw",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Verify pems are installed across your nodes\n",
        "\n",
        "!px get pems"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cX3ouK_oeXzJ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# View scripts you can run\n",
        "\n",
        "!px run -l"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nli-IwuCpxKx",
        "colab_type": "text"
      },
      "source": [
        "### Summary of resource consumption by pod"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rqvQdc-uo820",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Lifetime resource consumption by pod\n",
        "!px run px/pod_lifetime_resource "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TDHrVA8keyvQ",
        "colab_type": "text"
      },
      "source": [
        "### Health stats by pod"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "b2j0vaMbefjM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Get aggregate stats for all your pods\n",
        "\n",
        "!px run px/pod_stats"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4zhhKs1zfJ5o",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Check what arguments you can pass the script\n",
        "\n",
        "!px run px/pod_stats --help"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dSdmHEr5fZYU",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Let's restrict start-time for results\n",
        "\n",
        "!px run px/pod_stats -- -start_time -10s\n",
        "\n",
        "# Feel free to edit time window"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zICSIfDCfzqA",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Let's restrict results to specific namespace (Feel free to edit)\n",
        "\n",
        "!px run px/pod_stats -- -start_time -10s -pod_name kube-system/"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oc4wWj0On6_1",
        "colab_type": "text"
      },
      "source": [
        "### Health stats by node"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "h5Lxqntyn_Vn",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Get aggregate stats for all workloads running on the node\n",
        "\n",
        "!px run px/node_stats "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rv-2ac85oi7d",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Stats for a specific node\n",
        "\n",
        "!px run px/node_stats -- -node_name <add node name>"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XDJFASFHoHpo",
        "colab_type": "text"
      },
      "source": [
        "### Granular memory usage"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uOmlK91woTAp",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Process level memory consumption\n",
        "\n",
        "!px run px/pid_memory_usage"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "1Jq_0w6UpRIL",
        "colab": {}
      },
      "source": [
        "# Pod level memory consumption\n",
        "\n",
        "!px run px/pod_memory_usage"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "B-pZLwtqiji2",
        "colab_type": "text"
      },
      "source": [
        "### Granualar network metrics"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vEnBsdA0jZlb",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "### Network metrics by pod\n",
        "\n",
        "!px run px/network_stats\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Hi7RGC2WhLFt",
        "colab_type": "text"
      },
      "source": [
        "### Visualize results"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rcOF4xWKhvZx",
        "colab_type": "text"
      },
      "source": [
        "**Terminal UI:** You can append your scripts with `-o live` or run `px live` to view an interactive interface in your terminal"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "H4E3bqJ7hP3m",
        "colab_type": "text"
      },
      "source": [
        "**Web Browser UI:** Click on the URL printed at the bottom to view dashboard in Pixie \"Live\" web UI\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "J6ioq5UskZGy",
        "colab_type": "text"
      },
      "source": [
        "### Extending Pixie"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IkmTOLCQkrFv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Transform data into json to use tools like jq to pipe it into other tools\n",
        "\n",
        "!px run px/pod_stats -o json "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nQhloeXvk2lK",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Write custom scripts with .pxl extention and execute using px\n",
        "\n",
        "!px run -f <add your script name>"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WXRXEywrlWSY",
        "colab_type": "text"
      },
      "source": [
        "-------------------"
      ]
    }
  ]
}